package tcu.ead2021.leety.iotsystem_mqtt.mapper;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;
import tcu.ead2021.leety.iotsystem_mqtt.common.entity.mqtt.MQTTReturn;
import tcu.ead2021.leety.iotsystem_mqtt.mapper.provider.MQTTMapperProvider;

import java.util.List;

@Mapper
@Component("MQTTMapper")
@Repository
public interface MQTTMapper {

    /**
     * 插入数据mapper接口
     * 这是一个动态SQL语句，会根据设备名的不同，插入对应的数据表中
     */
    //@InsertProvider(type = MQTTMapperProvider.class, method = "CreateInsertSql")

    //@Insert("INSERT INTO MQTT (device,time,template,power,I1,I2,I3,I4) VALUES (#{device},#{time},#{power},#{I1},#{I2},#{I3},#{I4})")
    @Insert("INSERT INTO MQTT (device,time,template,power,I1,I2,I3,I4) VALUES (#{device},#{time}, #{template}, #{power}, #{I1}, #{I2}, #{I3}, #{I4})")
    void InsertData(String device, String time, String template, int power, float I1, float I2, float I3, float I4);

    @Select("SELECT * FROM MQTT WHERE device=#{device}")
    List<MQTTReturn> SelectData(String deviceName);

    @Delete("DELETE FROM MQTT WHERE time>=#{startTime} AND time<=#{endTime}")
    boolean DeleteData(String startTime,String endTime);
}
